<template>
  <el-form :inline="true" size="small" :model="query">
    <!-- 搜索 -->
    <el-form-item label="岗位名称">
      <el-input v-model="query.value" clearable placeholder="输入岗位名称搜索" @keyup.enter.native="toQuery"/>
    </el-form-item>
    <el-form-item label="岗位状态">
      <el-select v-model="query.enabled" clearable placeholder="状态" @change="toQuery">
        <el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button size="mini" type="primary" icon="el-icon-search" @click="toQuery">搜索</el-button>
    </el-form-item>
    <el-form-item>
      <!-- 新增 -->
      <div v-permission="['ADMIN','USERJOB_ALL','USERJOB_CREATE']">
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-plus"
          @click="add">新增</el-button>
        <eForm ref="form" :is-add="true" :dicts="dicts"/>
      </div>
    </el-form-item>
  </el-form>
</template>

<script>
import eForm from './form'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    },
    dicts: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      enabledTypeOptions: [
        { key: 1, display_name: '正常' },
        { key: 0, display_name: '禁用' }
      ]
    }
  },
  methods: {
    add() {
      this.$refs.form.getDepts()
      this.$refs.form.dialog = true
    },
    toQuery() {
      this.$parent.page = 1
      this.$parent.init()
    }
  }
}
</script>
